#!/bin/sh
# 等待网络接通
awaiting_network_connection()
{
	MAX_ATTEMPTS=20
	while [ $MAX_ATTEMPTS -gt 0 ]; do
		if ping -c 1 223.5.5.5 || ping -c 1 8.8.8.8; then
			break
		else
			sleep 3
			local MAX_ATTEMPTS=$(($MAX_ATTEMPTS-1))
		fi
	done
}
awaiting_network_connection >/dev/null
cd /userdisk/alist || exit 1
# 检查alist是否是第一次运行，是则把默认密码改成ABCD1234
if [ ! -d ./data ]; then
	./alist admin set ABCD1234
fi
./alist server >/dev/null 2>&1 &
sleep 5
# 放行5244端口，让alist能够被外网访问
ip6tables -L | grep "tcp dpt:5244"; [ $? != 0 ] && ip6tables -I INPUT -p tcp --dport 5244 -j ACCEPT
